<template>
  <a-modal v-model="visible" :width="1180" title="修改关系链" @ok="batchSelectNewItem">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :xl="24" :lg="24" :md="24" :sm="24">
            <a-radio-group v-model="type">
              <a-radio :value="1">
                更换上级
                <a-tooltip>
                  <template slot="title">
                    更换上级：指修改该用户所属的上级，同时将该用户的下级关系链将随该用户一起迁移至新上级的关系链下。
                  </template>
                  <a-icon type="question-circle" />
                </a-tooltip>
              </a-radio>
              <a-radio :value="2">
                迁移下级
                <a-tooltip>
                  <template slot="title">
                    迁移下级：指将原用户的所有下级关系链迁移至指定用户下，被指定的用户不能处于用户的下级关系链中。下级包含普通用户和粉丝。
                  </template>
                  <a-icon type="question-circle" />
                </a-tooltip>
              </a-radio>
            </a-radio-group>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="昵称">
              <a-input placeholder="请输入昵称" v-model="queryParam.nickname"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="手机号">
              <a-input placeholder="请输入手机号" v-model="queryParam.phone"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户身份">
              <a-select v-model="queryParam.level" @change="searchQuery">
                <a-select-option v-for="(item3,index3) in levelList" :key="index3" :value="item3.level">
                  {{item3.name}}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>

      <a-table ref="table" size="middle" bordered rowKey="id" :columns="columns" :dataSource="dataSource" :pagination="ipagination" :loading="loading"
        class="j-table-force-nowrap" @change="handleTableChange">

        <template slot="userSlot" slot-scope="text,record">
          <div style="display:flex;align-items: center;">
            <img :src="record.headUrl" style="width:50px;height:50px;">
            <div style="padding-left:5px;">
              <div>{{record.nickname}}</div>
              <div>{{record.phone}}</div>
              <div>注册时间：</div>
              <div>{{record.createTime}}</div>
            </div>
          </div>
        </template>
        <template slot="repSlot" slot-scope="text,record">
          <div>
            <span>积分：{{record.integral}}</span>
            <a-divider type="vertical" />
            <a @click="addIntegral(record.id)">加积分</a>
            <a-divider type="vertical" />
            <a @click="subIntegral(record)">减积分</a>
          </div>
          <div>余额：{{record.balance}}</div>
          <div>订单数量：{{record.orderNum}}</div>
          <div>支付金额：{{record.orderAmount}}</div>
        </template>

        <template slot="propSlot" slot-scope="text,record">
          <div>身份：{{record.role==0?'普通用户':'vip会员'}}</div>
          <div>类型：{{(record.isCompany==1||record.isMember==1)?'企业用户':'个人用户'}}</div>
          <div>性别：{{record.sex_dictText}}</div>
          <div>生日：{{record.dateBirth?record.dateBirth:'未知'}}</div>
          <div>地区：{{record.full_address}}</div>
        </template>

        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="55px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <!--标签和分组信息展示-->
        <template slot="crmTags" slot-scope="text,record">
          <div v-for="(item,index) in record.crmTags" :key="index" style="margin-bottom:2px;">
            <a-tag :color="item.type==1?'#87d068':'#108ee9'">
              {{item.name}}
            </a-tag>
          </div>
        </template>

        <template slot="crmGroups" slot-scope="text,record">
          <div v-for="(item,index) in record.crmGroups" :key="index" style="margin-bottom:2px;">
            <a-tag>
              {{item.name}}
            </a-tag>
          </div>
        </template>

        <span slot="action" slot-scope="text, record">
          <a v-if="selectionType=='radio'" @click="selectNewItem(record)">选择</a>
        </span>

      </a-table>
    </div>

  </a-modal>
</template>

<script>
import { putAction, getAction, postAction } from '@/api/manage'
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/MyJeecgListMixin'
import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'

export default {
  name: 'TipHandSetRef',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    JDictSelectTag,
  },
  data () {
    return {
      type: 1,
      pageCheckedKeys: [],
      noPageCheckedKeys: [],
      pageCheckedRows: [],
      noPageCheckedRows: [],
      visible: false,
      description: '分销员',
      // 表头
      columns: [
        {
          title: '头像',
          align: "center",
          dataIndex: 'headUrl',
          scopedSlots: { customRender: "imgSlot" }
        },
        {
          title: '昵称',
          align: "left",
          dataIndex: 'nickname'
        },
        {
          title: '手机号',
          align: "center",
          dataIndex: 'phone'
        },
        {
          title: '用户等级',
          align: "center",
          dataIndex: 'levelName'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: "/tipMember/otherList"

      },
      dictOptions: {},
      levelList: []
    }
  },
  created () {
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    open (id) {
      this.queryParam['fid'] = id
      this.type = 1
      this.loadData()
      this.getLevels()
    },
    getLevels () {
      var that = this
      getAction("/mallPlus/hmsHandConfig/list", {}).then((res) => {
        if (res.success) {
          that.levelList = res.result.records
        }
      })
    },
    setSelected () {
      this.pageCheckedKeys = []
      this.noPageCheckedKeys = []
      this.pageCheckedRows = []
      this.noPageCheckedRows = []
      for (let i = 0; i < this.checkedKeys.length; i++) {
        let isSelect = false
        for (let j = 0; j < this.dataSource.length; j++) {
          if (this.dataSource[j].id == this.checkedKeys[i]) {
            isSelect = true
          }
        }
        if (isSelect) {
          this.pageCheckedKeys.push(this.checkedKeys[i])
          this.pageCheckedRows.push(this.checkedRows[i])
        } else {
          this.noPageCheckedKeys.push(this.checkedKeys[i])
          this.noPageCheckedRows.push(this.checkedRows[i])
        }
      }
      this.selectedRowKeys = this.pageCheckedKeys
    },
    selectNewItem (val) {
      this.$emit('ok', val, this.type)
      this.visible = false
    },
    /* 弹框参照专用-批量选择选择 */
    batchSelectNewItem () {
      if (this.checkedRows.length > 0) {
        this.$emit('ok', this.selectionRows[0], this.type)
        this.visible = false
      } else {
        this.$message.warning("请先选择")
      }

    },
    initDictConfig () {
    }
  }
}
        </script>
<style scoped>
@import '~@assets/less/common.less';
</style>
